<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>mixin内部继承与super关键字</title>
  </head>
  <body></body>
  <script>
    function extend(sub, sup) {
      sub.prototype = Object.create(sup.prototype);
      Object.defineProperty(sub.prototype, "constructor", {
        value: sub,
        enumerable: false
      });
    }
    function User(name, age) {
      this.name = name;
      this.age = age;
    }
    User.prototype.show = function() {
      console.log(this.name, this.age);
    };
    const Request = {
      ajax() {
        return "请求后台";
      }
    };

    const Credit = {
      __proto__: Request,
      total() {
        //super=this.__proto__
        console.log(super.ajax() + "统计积分");
      }
    };

    const Address = {
      getAddress() {
        console.log("获取收货地址");
      }
    };

    function Admin(...args) {
      User.apply(this, args);
    }
    extend(Admin, User);
    Object.assign(Admin.prototype, Request, Credit, Address);
    let hd = new Admin("向军", 19);
    hd.show();
    hd.total(); //统计积分
    hd.ajax(); //请求后台
    hd.getAddress();

    console.log(hd);
    console.log(Credit);
  </script>
</html>
